package com.bonorsoft.system.mapper;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.bonorsoft.system.entity.SysMoney;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bonorsoft.system.entity.SysSet;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author WilliamYe
 * @since 2020-07-23
 */
public interface SysMoneyMapper extends BaseMapper<SysMoney> {

    @Select("select money from sys_set")
    String getMoney();

    @Select("select stroge from sys_set")
    Integer getStroge();

    @Select("select top_number from sys_set")
    Integer getTop();

    @Update("update sys_set set stroge = stroge + 1 where top_number >= stroge + 1")
    int subStroge();

    @Update("update sys_set set stroge = stroge - 1")
    void addStroge();

    @Select("select max(sequence) from sys_money")
    Integer getOrderMax();

    @Select("select * from sys_set")
    SysSet getBasic();

    @Insert("INSERT INTO sys_set (id, start_time, end_time ) VALUES (#{ id },#{ startTime }, #{ endTime })")
    void saveBasic(String id, Date startTime, Date endTime);

    @Update("update sys_set set start_time = #{ startTime }, end_time = #{ endTime } where id = #{ id }")
    void updateBasicById(String id, Date startTime, Date endTime);

    void myupdate(@Param("entity") SysMoney money, @Param(Constants.WRAPPER) UpdateWrapper<SysMoney> mUpdateWrapper);

    @Update("update sys_set set stroge = #{ sheng }")
    void upateStroge(Integer sheng);

    @Insert("insert into sys_call_back(id, call_back) values(#{ no }, #{ xmlStr }) ")
    void insertCallBck(String no, String xmlStr);

    @Update("update sys_money m, (select max(sequence) + 1 max from sys_money) mm set m.pay_status = '1', m.pay_time = NOW(), m.sequence = IFNULL(mm.max,1) where m.openid = #{ openid } and m.out_trade_no = #{ ordersSn }")
    void updateStatusBySql(String openid, String ordersSn);
}
